package com.stu.reflection.factory;

public class ReflectionFactory2 {
  private ReflectionFactory2() {}
  // 简写形式没有输出，可能和泛型擦除有关
  // @SuppressWarnings("unchecked")
  // public static <T> T getInstance(String classFullName, Class<T> father) {
  //   try {
  //     return (T)Class.forName(classFullName).getDeclaredConstructor().newInstance();
  //   } catch (Exception e) {
  //     e.printStackTrace();
  //     return null;
  //   }
  // }
  // 解决工厂类与接口的耦合
  @SuppressWarnings("unchecked")
	public static <T> T getInstance(String classFullName,Class<T> fatherInterface) {
		T t = null;
		try {
			t = (T) Class.forName(classFullName).getDeclaredConstructor().newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return t;
	}
}
